package beautiful.butterfly.schedule.task_manager;


import beautiful.butterfly.schedule.TaskItemAndParameter;
import org.apache.zookeeper.data.Stat;

import java.util.List;
import java.util.Map;


public interface IDataManager {
    public long zooKeeperCurrentTimeMillis();


    public List<TaskItemAndParameter> getTaskItemAndParameterList(String taskType, String uuid) throws Exception;


    public List<TaskItem> loadTaskItemList(String taskType) throws Exception;


    public void releaseDealTaskItem(String taskType, String uuid) throws Exception;

    public int getTaskItemCount(String taskType) throws Exception;


    public TaskType loadBaseTaskType(String taskType) throws Exception;


    public int clearExpireServers(String taskType, long expireTime) throws Exception;

    /**
     * @param serverIdList 可分配的
     */
    public int createTaskItemIfNotFind(String taskType, List<String> serverIdList) throws Exception;

    public List<TaskHandler> getTaskHandlerList(String taskType) throws Exception;

    public List<String> loadServerIdList(String taskType) throws Exception;


    public void assignTaskItem(String taskType, String currentUuid, int maxTaskItemsOfOneThreadGroup, List<String> serverIdList) throws Exception;


    public boolean refreshHeartBeatTimeAndVersion(TaskHandler taskHandler) throws Exception;

    public void registerTaskHandler(TaskHandler taskHandler) throws Exception;

    public void unRegisterTaskHandler(String taskType, String uuid) throws Exception;

    public void clearExpireTaskTypeRunningInfo(String baseTaskType, String serverUUID, double expireDateInternal) throws Exception;

    public boolean isLeaderServerId(String uuid, List<String> serverList);

    //
    public void pauseTaskType(String baseTaskType) throws Exception;

    public void resumeTaskType(String baseTaskType) throws Exception;

    //
    public List<TaskType> getBaseTaskTypeList() throws Exception;


    public void clearTaskType(String baseTaskType) throws Exception;


    public void createBaseTaskType(TaskType baseTaskType) throws Exception;

    public void updateBaseTaskType(TaskType baseTaskType) throws Exception;

    public List<TaskTypeRuntimeInfo> getTaskTypeRunInfoList(String baseTaskType) throws Exception;


    public void deleteTaskType(String baseTaskType) throws Exception;


    public List<TaskHandler> getTaskHandlerList(String baseTaskType, String ownSign, String ip, String orderStr)
            throws Exception;


    public List<TaskHandler> getTaskHandlerListByMachineId(String managerFactoryUuid) throws Exception;


    public void createTaskItemIfNotFind(TaskItem[] taskItems) throws Exception;


    public void updateTaskItemStatus(String taskType, String taskItem, Status status, String message) throws Exception;


    public void deleteTaskItem(String taskType, String taskItem) throws Exception;


    public void createTaskItems(String baseTaskType, String ownSign, String uuid) throws Exception;

    public void createTaskType(String baseTaskType, String ownSign) throws Exception;


    public boolean isLeaderServer(String baseTaskType, String ownSign) throws Exception;

    public void setTaskItemsWithServerId(String baseTaskType, String taskType, String uuid) throws Exception;

    public String getLeaderServerId(List<String> serverNameList);

    public long updateTaskItemFlag(String taskType) throws Exception;

    public long getTaskItemStatVersion(String taskType) throws Exception;

    public Map<String, Stat> getServerIdToStatMap(String taskType) throws Exception;

}
